
import java.io.IOException;
import java.sql.Timestamp;
import java.util.concurrent.Callable;

public class TakeScreen implements Callable<ScreenShotVO> {

	private int reportsId = 0;
	
	private String shoutUrl = null;
	
	private String filepath = null;
	
	private String mirrorpath = null;
	
	public TakeScreen(int reportsId, String shoutUrl, String filepath, String mirrorpath) {
		this.reportsId = reportsId;
		this.shoutUrl = shoutUrl;
		this.filepath = filepath;
		this.mirrorpath = mirrorpath;
	}
	
	@Override
	public ScreenShotVO call() {
		Process p = null;
		try {
			String cmd = "iecapt --url=" + shoutUrl + " --out="+mirrorpath + "\\" + reportsId + ".png";
			p = Runtime.getRuntime().exec(cmd);
			int retVal = p.waitFor();
			if( retVal == 0 ) {
				ScreenShotVO screenShotVO = new ScreenShotVO();
				screenShotVO.setReportsId(reportsId);
				screenShotVO.setShoutUrl(shoutUrl);
				screenShotVO.setFileName(filepath + "/" + reportsId + ".png");
				screenShotVO.setTimestamp(new Timestamp(System.currentTimeMillis()));
				return screenShotVO;
			}
		} catch (IOException e) {
			e.printStackTrace();
		} catch (InterruptedException e) {
			Thread.currentThread().interrupt();
		}  finally {
			if( p != null )
				p.destroy();
		}
		return null;
	}

	public int getReportsId() {
		return reportsId;
	}

	public void setReportsId(int reportsId) {
		this.reportsId = reportsId;
	}

	public String getShoutUrl() {
		return shoutUrl;
	}

	public void setShoutUrl(String shoutUrl) {
		this.shoutUrl = shoutUrl;
	}
}
